package com.ruoyi.project.wms.basedata.provider.controller;

import java.util.List;

import com.ruoyi.project.wms.basedata.provider.domain.WmsProvider;
import com.ruoyi.project.wms.basedata.provider.service.IWmsProviderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author ruoyi
 * @date 2020-09-29
 */
@Controller
@RequestMapping("/basedata/provider")
public class WmsProviderController extends BaseController
{
    private String prefix = "wms/basedata/provider";

    @Autowired
    private IWmsProviderService wmsProviderService;

    @RequiresPermissions("basedata:provider:view")
    @GetMapping()
    public String provider()
    {
        return prefix + "/provider";
    }

    /**
     * 查询供应商列表
     */
    @RequiresPermissions("basedata:provider:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsProvider wmsProvider)
    {
        startPage();
        List<WmsProvider> list = wmsProviderService.selectWmsProviderList(wmsProvider);
        return getDataTable(list);
    }

    /**
     * 导出供应商信息列表
     */
    @RequiresPermissions("basedata:provider:export")
    @Log(title = "导出供应商信息列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsProvider wmsProvider)
    {
        List<WmsProvider> list = wmsProviderService.selectWmsProviderList(wmsProvider);
        ExcelUtil<WmsProvider> util = new ExcelUtil<WmsProvider>(WmsProvider.class);
        return util.exportExcel(list, "provider");
    }

    /**
     * 新增供应商信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商信息
     */
    @RequiresPermissions("basedata:provider:add")
    @Log(title = "新增保存供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsProvider wmsProvider)
    {
        return toAjax(wmsProviderService.insertWmsProvider(wmsProvider));
    }

    /**
     * 修改供应商信息
     */
    @GetMapping("/edit/{pid}")
    public String edit(@PathVariable("pid") Long pid, ModelMap mmap)
    {
        WmsProvider wmsProvider = wmsProviderService.selectWmsProviderById(pid);
        mmap.put("wmsProvider", wmsProvider);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商信息
     */
    @RequiresPermissions("basedata:provider:edit")
    @Log(title = "修改保存供应商信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsProvider wmsProvider)
    {
        return toAjax(wmsProviderService.updateWmsProvider(wmsProvider));
    }

    /**
     * 删除供应商信息
     */
    @RequiresPermissions("basedata:provider:remove")
    @Log(title = "删除供应商信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsProviderService.deleteWmsProviderByIds(ids));
    }
}
